<template>
     <el-dialog append-to-body :visible.sync="open" width="60%" :before-close="handleClose" class="demandFormVisible_dialog" >
          <template slot="title">
               <div style="">{{ celldbData.label }}</div>
          </template>
          <tableList v-if="tableHeaderList.length > 0" :tableHeaderList="tableHeaderList" :tableData="tableData"
               :loading="loading" :tableHeight="tableHeight" @celldblclick="celldblclick" @sortChange="sortChange"
               :isSelection="isSelection" :isProjectJuanList="isProjectJuanList" @handledeitTap="handledeitTap">
          </tableList>
          <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
               @pagination="getlistPost" />


          <!--start  组件详情 -->
          <jianDetailsOpen v-if="jianDetailsOpen" :open="jianDetailsOpen" :celldbData="celldbData2"
               @detailsHandleClose="detailsHandleClose">
          </jianDetailsOpen>
          <!--end 组件详情 -->
          <!-- start 组卷\项目详情 -->
          <juanDetailsOpen v-if="juanDetailsOpen" :open="juanDetailsOpen" :celldbData="celldbData2"
               @detailsHandleClose="detailsHandleClose" ></juanDetailsOpen>
          <!-- end 组卷\项目详情 -->

          <!-- start 组卷著录、修改 -->
          <juandeit v-if="juanOpen" :open="juanOpen" :openInfo="openInfo" @closeDelDialog="closeDelDialog"
               @submitDetail="submitDetail" :isParams="isParams" :isZUXIU="2" :isShow="isShow"></juandeit>
          <!-- end  组卷著录、修改-->
     </el-dialog>
</template>
<script>
import { getlistbyparentId, getthbytreenodeHeaderList, getDataInfo } from "@/api/archive/fileCollection/offlinReception.js";
import { getdetaillist, updateshending, updateliyou, updatebeizhu } from "@/api/archive/archivalAppraisal/openness/openArchivesAppraisal"//获取开放鉴定初审和复审列表项目内案卷列表/获取卷内件列表接口
import { getGroupTree } from "@/api/archive/archivesCategory.js"
import '@/assets/styles/index.scss' // global css
import tableList from "@/components/tableList/index.vue"
import jianDetailsOpen from '@/components/componentsJianDetails/index.vue' //件详情
import juanDetailsOpen from '@/components/componentsJuanDetails/index.vue' //卷详情
import { getLastIndexOf } from "@/utils/index.js"
import juandeit from "@/views/archive/fileCollection/fileOrganization/fileQrganizationTobeArchived/juandeit.vue" //卷添加修改弹窗
export default {
     name: 'juan-component',

     props: ["celldbData", "open", "isDelete", 'openInfo', 'isShow', 'isParams'],
     archive_Dicts: ['MJ', 'BGQX', 'IS_OPENS', 'CSLY'],
     components: {
          tableList,
          jianDetailsOpen,
          juanDetailsOpen,
          juandeit
     },
     watch: {
          celldbData: {
               handler(valNew) {
                    this.tableHeightData();
                    this.dataInfoCell = valNew;
                    this.getGroupTreePost();
               }, immediate: true
          },
     },
     data() {
          return {
               celldbData2: {},
               demandFormVisible: true,
               visibleOpen: false, //文件、案卷、项目信息展示效果是否弹窗
               activeName: "1",//默认显示第一个'基本数据=1  过程数据=2  固化信息=3 其他数据=4'
               dataInfo: [], //文件、案卷、项目信息数据显示
               tableHeaderList: [], //table表头数据
               tableData: [],//table列表数据
               total: 0,
               loading: false,
               tableHeight: "",
               jianDetailsOpen: false,//件详情弹窗
               juanDetailsOpen: false,//卷详情弹窗
               dataInfoCell: "",
               isSelection: false,  //复选框是否显示 false 隐藏  true 显示
               isProjectJuanList: true, //操作  （修改是否显示） true 显示   false隐藏
               // 查询参数
               queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    propertyName: [],
                    propertyValue: [],
                    state: 1,
                    cate: []
               },
               subString: "",
               categoryInfo: "",
               rowInfo: "",
               juanOpen: false
          }
     },
     methods: {



          /**点击树节点,获取table表头数据 */
          getlistHeaderPost(categoryInfo) {
               this.queryParams.isDel = this.dataInfoCell.isDel;
               this.queryParams.categoryId = this.dataInfoCell.categoryId;
               this.queryParams.menuId = this.dataInfoCell.menuId;
               if (this.dataInfoCell.substr == undefined) {
                    if (getLastIndexOf(this.dataInfoCell.sub_table_name) == "F") {  //F 件
                         this.queryParams.subTableName = ""
                    } else if (getLastIndexOf(this.dataInfoCell.sub_table_name) == "V") { //卷
                         this.queryParams.subTableName = categoryInfo.fileTableName
                    } else { //项目
                         this.queryParams.subTableName = categoryInfo.folderTableName
                    }
               } else {
                    this.queryParams.subTableName = this.dataInfoCell.substr
               }
               this.subString = getLastIndexOf(this.queryParams.subTableName)
               getthbytreenodeHeaderList(this.queryParams).then(response => {
                    this.tableHeaderList = response.rows;
                    var fields = []
                    for (var i in response.rows) {
                         fields.push(response.rows[i].FIELD_NAME)
                    }
                    this.queryParams.fields = fields.toString();
                    this.queryParams.parentId = this.dataInfoCell.id;
                    this.queryParams.level = this.dataInfoCell.level;
                    // console.log(this.chuFushenParams, "klsdfjklsliuhaor")
                    this.getlistPost();
               });
          },
          /** 点击树节点,获取table数据*/
          getlistPost() {

               getlistbyparentId(this.queryParams).then(response => {
                    this.tableData = response.rows;
                    this.total = response.total;
                    this.loading = false;
               });


          },


          //档案门类树门类根据categoryID回显
          getGroupTreePost() {
               getGroupTree(this.dataInfoCell.categoryId).then(response => {
                    this.categoryInfo = response.data;
                    this.getlistHeaderPost(response.data)
               });
          },
          //动态设置table的高度
          tableHeightData() {
               this.$nextTick(
                    () => {
                         let h = 650;

                         //  h = h + 100
                         if (this.$refs.queryForm) { // 页面上如果有面包屑区域徐减去它的高度
                              h = h - this.$refs.queryForm.$el.offsetHeight
                         }

                         if (this.$refs.refbut) { // 页面上如果有分页区域徐减去它的高度
                              h = h - this.$refs.refbut.$el.offsetHeight
                         }
                         this.tableHeight = h > 310 ? h : 310 // 根据自己项目定高度
                         return h
                    }
               )
          },
          //点击获取文件/案卷/项目信息
          onInfoTap(infotype, datatype) {
               var that = this;
               that.visibleOpen = true;
               this.activeName = "1";
               this.getInfoPost(infotype, datatype)
          },

          getInfoPost(infotype, datatype) {
               getDataInfo({
                    infotype: infotype,
                    datatype: datatype,
                    categoryId: this.dataInfoCell.categoryId,
                    id: this.dataInfoCell.id,

               }).then(res => {
                    if (res.data.datalist.length > 0) {
                         this.datalistAll = res.data.datalist
                         this.dataInfo = res.data.datalist.filter(res => {
                              return res.ZSFL == this.activeName
                         })
                    }

               })
          },
          tabVisibleClick(tab, event) {
               var that = this;
               this.activeName = tab.name;
               // console.log(this.datalistAll, "+++++++++++++")
               this.dataInfo = this.datalistAll.filter(res => {
                    return res.ZSFL == this.activeName
               })

          },
          //关闭
          handleClose() {
               this.$emit("detailsHandleClose")
          },

          //双击列表进入件详情页面
          celldblclick(row) {
               var subTableName = ""
               var level = "";
               var label = "";
               if (getLastIndexOf(this.queryParams.subTableName) == "F") {  //F 件
                    subTableName = ""
                    level = 0
                    label = row.TITLE;
               } else if (getLastIndexOf(this.queryParams.subTableName) == "V") { //卷
                    subTableName = this.categoryInfo.fileTableName
                    level = 1
                    label = row.TITLE;
               } else { //项目
                    subTableName = this.categoryInfo.folderTableName
                    level = 3
                    label = row.XMMC;
               }
               console.log(this.queryParams)

               this.celldbData2 = {
                    id: row.ID,
                    categoryId: this.queryParams.categoryId,
                    menuId: this.queryParams.menuId,
                    // substr: subTableName,
                    label: this.dataInfoCell.label,
                    level: 1,
                    sub_table_name: this.queryParams.subTableName,
                    ifSub_table_name: this.dataInfoCell.ifSub_table_name,
                    isDel: this.dataInfoCell.isDel,
                    tableHeaderList: this.tableHeaderList
               }




               this.$nextTick(() => {
                    if (this.subStr == "F") {  //F 进入件详情
                         this.jianDetailsOpen = true;
                    } else { //进入卷详情 和项目详情
                         this.juanDetailsOpen = true
                    }
               })

          },





          //关闭组件详情页面
          detailsHandleClose() {
               this.jianDetailsOpen = false;
               this.juanDetailsOpen = false;


          },
          submitDetail() {
               this.juanOpen = false;
               this.getlistPost();
          },
          //关闭卷详情
          closeDelDialog() {
               this.juanOpen = false;
               this.getlistPost();
          },


          //排序
          sortChange(val) {
               this.queryParams.order = val;
               this.getlistPost();
          },

          //修改卷详情
          handledeitTap(data) {
               this.openInfo['ids'] = data.ID;
               this.openInfo.subStr="X"
               this.openInfo.button="xmajzl"
               // console.log(this.openInfo, data)
               this.juanOpen = true;

               console.log(this.openInfo)
          },
     }
}
</script>

<style lang="less" scoped>
ul,
li,
p,
div {
     padding: 0;
     margin: 0;
}

/deep/.el-tabs--border-card>.el-tabs__content {
     padding: 0 !important;
}









.headerInfoButton {
     position: absolute;
     top: 16px;
     right: 60px;
}

::v-deep .el-dialog__body {
     padding: 10px 20px 25px !important;
}

.margin_t {
     margin-top: 10px;
}

.text-ellipsis {
     overflow: hidden;
     white-space: nowrap;
     text-overflow: ellipsis;
     -o-text-overflow: ellipsis;
}

.flex-row {
     display: flex;
     flex-direction: row;
}

.flex-row-bowtte {
     display: flex;
     flex-direction: row;
     justify-content: space-between
}

.itemList {
     padding: 10px 15px 10px;
}

.itemList p {
     line-height: 38px;
     display: block;
}

.demandFormVisible_dialog {
     .el-dialog__wrapper {
          pointer-events: none;

          ::v-deep .el-dialog {
               pointer-events: auto;
          }
     }
}
</style>
